package com.lonty.intelligence.controller;

import com.lonty.intelligence.api.Result;
import com.lonty.intelligence.api.ResultCode;
import com.lonty.intelligence.model.LicensePlate;
import com.lonty.intelligence.service.LicensePlateService;
import com.lonty.intelligence.vo.LicensePlateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author 陈璇
 * @Date 2020/5/11 14:15
 * @Version 1.0
 */
@RestController
@RequestMapping("app/licensePlate")
@Validated
@Api(tags = "车牌接口", produces = "application/json")
public class LicensePlateController {

    @Resource
    private LicensePlateService licensePlateService;

    @ApiOperation(value = "保存车牌", httpMethod = "POST")
    @PostMapping("saveLicensePlate")
    public Result saveLicensePlate(@ModelAttribute LicensePlateVo licensePlateVo){
        LicensePlate licensePlate = licensePlateService.saveLicensePlate(licensePlateVo);
        if(licensePlate != null){
            return Result.builder().data(licensePlate).build();
        }
        return Result.builder(ResultCode.OPERATION_ERROR).build();
    }

    @ApiOperation(value = "根据住户ID获取车牌", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "householdId", value = "住户ID",dataType = "string", paramType = "query", required = true)
    })
    @PostMapping("getByHouseholdId")
    public Result getByHouseholdId(String householdId){
        return Result.builder()
                .data(licensePlateService.getByHouseholdId(householdId))
                .build();
    }

}
